package com.company.OfferGuide;

public class 二维数组中的查找 {

    public static void main(String[] args) {
        System.out.println(findNumberIn2DArray(new int[][]{{1, 1}}, 0));
    }

    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix == null || matrix.length == 0) return false;

        int row = 0,col = matrix[0].length - 1;

        while (row <= matrix.length && col >= 0) {
            if (target == matrix[row][col]) {
                return true;
            } else if (target > matrix[row][col]) {
                row++;
            } else {
                col--;
            }
        }

        return false;
    }

}
